package com.gengine.utils
{
	import com.gengine.keyBoard.*;
	import com.mui.controls.*;
	import flash.display.*;
	import flash.events.*;
	import flash.net.*;
	import flash.utils.*;
	
	public class TimerTest extends Sprite
	{
		private var _sTime:int;
		private var _dsTime:int;
		private var _eTime:int;
		private var _deTime:int;
		private var _i:int = 1;
		private var _frame:int = 12;
		private var _delay:int = 80;
		private var _d:int;
		private var _stage:Stage;
		private var _num:int = 0;
		private var _noDelay:int = 0;
		private var _isAlert:Boolean = false;
		
		public function TimerTest(param1:Stage) : void
		{
			this._frame = param1.frameRate;
			this._stage = param1;
			
		}
		
		public function start() : void
		{
			this._sTime = getTimer();
			this._dsTime = new Date().time;
			this._stage.addEventListener(Event.ENTER_FRAME, this.onEventFrameHandler);
			
		}
		
		private function onEventFrameHandler(event:Event) : void
		{
			this._i = this._i + 1;
			if (this._i > 20)
			{
				this._i = 1;
				this.testChangeTime();
			}
			
		}
		
		private function testChangeTime() : void
		{
			this._eTime = getTimer();
			this._deTime = new Date().time;
			this._i = this._eTime - this._sTime;
			this._d = this._deTime - this._dsTime;
			if (Math.abs(this._i - this._d) > this._delay)
			{
				this._noDelay = 0;
				this._num = this._num + 1;
				if (this._num > 5)
				{
					if (this._isAlert == false)
					{
						KeyBoardManager.instance.cancelListener();
						this._isAlert = true;
						Alert.show("检测到当前系统时间被修改，若是手动修改，\n请刷新后再进行游戏", null, 0, null, this.close);
						
					}
				}
			}
			this._sTime = this._eTime;
			this._dsTime = this._deTime;
			
		}
		
		private function close(param1:int) : void
		{
			this._isAlert = false;
			navigateToURL(new URLRequest("javascript:location.reload();"), "_self");
			this._stage.removeEventListener(Event.ENTER_FRAME, this.onEventFrameHandler);
			
		}
		
	}
}
